package com.forum.jspgenerator;

import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

import com.forum.domain.Remind;
import com.forum.domain.RemindDAO;
import com.forum.domain.User;

public class GenerateR_M {

	private int id;
	private User user;
	private RemindDAO reminddao;

	public void setReminddao(RemindDAO reminddao) {
		this.reminddao = reminddao;
	}

	private int count;

	List<Remind> remindlist = new LinkedList();

	// List<Message> messagelist = new LinkedList();

	public GenerateR_M(User user) {
		this.user = user;
	}

	public List<Remind> getReminds() {
		generateReminds();
		return remindlist;
	}

	private void generateReminds() {
		remindlist = reminddao.findByProperty("userByUserId", user.getUserid());
		ComparatorRemind comparator = new ComparatorRemind();
		Collections.sort(remindlist, comparator);
		count = remindlist.size();
	}

}

class ComparatorRemind implements Comparator {

	public int compare(Object o1, Object o2) {
		// TODO Auto-generated method stub
		Remind r1 = (Remind) o1;
		Remind r2 = (Remind) o2;
//		逆序
//		return r2.getReply().getTime().compareTo(r1.getReply().getTime());
		return r1.getReply().getTime().compareTo(r2.getReply().getTime());
	}

}
